package com.idanchuang.component.mq.amqp;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.PostConstruct;

/**
 * @author yjy
 * @date 2019/12/4 10:50
 **/
@SpringBootApplication
@RestController
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @PostConstruct
    public void callback() {
        rabbitTemplate.setConfirmCallback(( correlationData, ack, cause) -> {
           System.out.println("MessageConfirm correlationData:"+correlationData+",ack:"+ack+",cause:"+cause);

        });
    }

    @RequestMapping("testMq")
    @ResponseBody
    public String testMq(String msg) {
        rabbitTemplate.convertAndSend(msg);
        return "ok";
    }



}
